Title Banner

Previous Book Contents Book Index Next

Inside Macintosh: QuickDraw GX Printing Extensions and Drivers /
Chapter 5 - Printing Functions for Message Overrides / Using the Printing Functions


Segmenting Your Driver Code

The smallest code segment that you can have with the messaging architecture consists of the code required to override a single message. However, in some cases you might want to have multiple code segments for a single message. For example, you might need a number of functions to override a message like GXRenderPage, which performs a lot
of work.

QuickDraw GX provides a segment handler that you can use to divide your message override code into multiple segments. The segment handler allows you to construct a special 32-bit dispatch selector, which allows you to access functions in other code segments. The dispatch selector contains the segment's resource ID and the offset in that segment to the start of your function.

The PRINTINGDISPATCH macro constructs the dispatch selector and dispatch code for you, which allows you to call the function just as you would any other function. All that you need to do is define the macro. PRINTINGDISPATCH assumes that you start your segment with a long-aligned jump table, just like the jump tables that you use for your printing message overrides, as described in the section "The Jump Table" beginning on page 2-9 in the chapter "Printing Extensions." It also assumes that each entry in the table is 4 bytes long.

You define the dispatch macro with the segment ID and routine selector. For example, if your code is the third routine in a segment (it is at offset 12 in the segment) in a printer driver ('pdvr') resource with an ID of 2, you define your macro as shown here:

OSErr MyRenderingRoutine (long param1, Ptr param2)
  = PRINTINGDISPATCH(2, 3);
All segment dispatches must return a value of type OSErr. If your function does not generate errors, you must still declare it to return an OSErr value and have the function return the constant noErr. You can then call your function as usual and also get free type-checking, as in this example:

   anErr = MyRenderingRoutine(p1, p2);   /* free type-checking */
You can call across segments by constructing your own 32-bit selector and calling the GXPrintingDispatch function directly. This method does not give you free type-checking and makes your code more complicated. However, the results are identical. For example, you could call the MyRenderingRoutine function using the following method:

  #define kMyRenderRoutineSelector 0x0002000C
   /* no type checking for the following call */
  anErr = GXPrintingDispatch(kMyRenderRoutineSelector, p1, p2);
The GXPrintingDispatch function is described on page 5-38.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996




Navigation graphic, see text links

Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help